package logic

import (
	"context"
	"jd.com-user-system/userrpc/userrpc"

	"jd.com-user-system/userapi/internal/svc"
	"jd.com-user-system/userapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.UserRpc.Update(l.ctx, &userrpc.UpdateRequest{
		Id:          req.Id,
		Img:         req.Img,
		AccountName: req.AccountName,
		Nickname:    req.Nickname,
		Sex:         req.Sex,
		Data:        req.Data,
		CaptchaCode: req.CaptchaCode,
		SmsCode:     req.SmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: "修改失败" + err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Code:    "200",
		Data:    update,
	}, nil
}
